package sorts

import "sort"

//排序
//排序字符串类型,string
//[0 1 10 100 11 2 20]
func SortString(list []string, desc ...bool) {
	sort.Sort(newSortString(list, len(desc) > 0 && desc[0]))
}




type SortStringModel struct {
	list []string
	desc bool
}

func newSortString(list []string, desc bool) SortStringModel {
	return SortStringModel{
		list: list,
	}
}

//实现自带排序接口
func (this SortStringModel) Len() int {
	return len(this.list)
}

//实现自带排序接口
func (this SortStringModel) Less(i, j int) bool {
	b := this.list[i] < this.list[j]
	if this.desc {
		b = !b
	}
	return b
}

//实现自带排序接口
func (this SortStringModel) Swap(i, j int) {
	this.list[i], this.list[j] = this.list[j], this.list[i]
}
